package com.hnkywl.sts.service.taskdeal;

import com.hnkywl.sts.dao.base.ZddxDao;
import com.hnkywl.sts.service.base.DxpzService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.sql.SQLException;

/**
 * 发送自动短信
 * Created with IntelliJ IDEA.
 * User: xx
 * Date: 13-6-20
 * Time: 下午12:31
 * To change this template use File | Settings | File Templates.
 */
@Service
@Transactional
public class DoSendZddx {
    //短信服务
    DxpzService dxpzService;

    //获取信息
    ZddxDao zddxDao;

    /**
     * 发送短信
     */
    public void manageSms() {
        manageSmsKc();
        manageSmsCgXs();
        manageSmsCw();
    }

    /**
     * 短信：黑色金属现货库存X吨（本部X，上海X，合肥X。。。）；
     * |轨道附件#1#本部0、武汉分公司1|黑色金属#-77#本部0、武汉分公司-137、昆明分公司60|黑色金属制品#2,005#本部0、武汉分公司2,005|橡塑制品#87#本部0、上海子公司87
     */
    public void manageSmsKc() {
        try {
            String[] ret = zddxDao.getKc();
            Integer count = 0;
            String strTmp = "";
            if (ret.length > 1) {
                String msmInfo = "";
                count = Integer.parseInt(ret[0]);
                strTmp = ret[1];
                String[] nodeList = strTmp.split("\\|");
                for (int i = 0; i < nodeList.length; i++) {
                    String[] cell = nodeList[i].split("#");
                    if (cell.length > 2) {
                        msmInfo += cell[0] + "现货库存" + cell[1] + "吨（" + cell[2] + "); ";
                    }
                }
                dxpzService.sendMsg("smskc", msmInfo);
            }
        } catch (SQLException e) {
            e.printStackTrace();  //To change body of catch statement use File | Settings | File Templates.
        }
    }

    /**
     * 今日采购额X（月累计X） 今日销售额X（月累计X）
     *
     * @return
     */
    public void manageSmsCgXs() {
        try {
            String[] ret = zddxDao.getCgXs();

            if (ret.length > 1) {
                String[] cg = ret[0].split("\\|");
                String[] bg = ret[1].split("\\|");
                String[] xs = ret[2].split("\\|");
                dxpzService.sendMsg("smscgxs", cg[0], cg[1], bg[0], bg[1], xs[0], xs[1]);
            }
        } catch (SQLException e) {
            e.printStackTrace();  //To change body of catch statement use File | Settings | File Templates.
        }
    }

    /**
     * 今日财务收X（现汇X，银票X、商票X）付X（现汇X，银票X、商票X）
     *
     * @return
     */
    public void manageSmsCw() {
        try {
            String[] ret = zddxDao.getCw();
            if (ret.length > 1) {
                String[] cws = ret[0].split("\\|");
                String[] csf = ret[1].split("\\|");
                dxpzService.sendMsg("smscw", cws[0], csf[0], cws[1], csf[1]);
            }
        } catch (SQLException e) {
            e.printStackTrace();  //To change body of catch statement use File | Settings | File Templates.
        }
    }


    /////////////////////////////////////////////////////////////////////////
    @Autowired
    public void setDxpzService(DxpzService dxpzService) {
        this.dxpzService = dxpzService;
    }

    @Autowired
    public void setZddxDao(ZddxDao zddxDao) {
        this.zddxDao = zddxDao;
    }
}
